package com.smartHire.controller.User.Order_goods;

import com.alibaba.fastjson.JSONObject;
import com.smartHire.domain.Order;
import com.smartHire.service.OrderService;
import com.smartHire.service.Order_goodsService;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "ShowMyGoodsServlet", value = "/ShowMyGoodsServlet")
public class ShowMyGoodsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");

        String type= request.getParameter("type");
        String open_id = request.getParameter("open_id");
        String shop_name=request.getParameter("shop_name");

        WebApplicationContext ctx = null;
        //使用框架中的方法，获取容器对象
        ServletContext sc = getServletContext();
        ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
        System.out.println("容器对象的信息========"+ctx);

        try {
            OrderService orderService = (OrderService) ctx.getBean("orderService");

            if(shop_name==null) {
                List list = orderService.queryOrderByType(type, open_id);

                String jsonStr = JSONObject.toJSONString(list);
                response.getWriter().write(jsonStr);
            }
            else{
                List list = orderService.queryOrderByShop(type, shop_name);
                String jsonStr = JSONObject.toJSONString(list);
                response.getWriter().write(jsonStr);
            }




        }catch (Exception e)
        {
            e.printStackTrace();
        }

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
